test(coverage): provision handlers 75→80% via bufconn fake provisioner#156
Merged
Merged
Conversation
…ufconn fake provisioner The provision happy-paths (provisionDB/provisionCache/provisionNoSQL/ provisionQueue) call a concrete *provisioner.Client over gRPC with no test seam, so they returned 503 in tests and stayed uncovered (the prior agent maxed at ~75%). This adds a minimal, production-safe seam — provisioner.NewClientFromConn(conn, secret) — that builds a Client around an already-dialed grpc.ClientConn. Tests stand up an in-process fake ProvisionerServiceServer on a google.golang.org/grpc/test/bufconn listener and inject it into the db/cache/nosql/queue handlers, so the `provClient != nil` arms actually execute. New coverage: - gRPC provision success (anon + authenticated) for db/cache/nosql/queue, tier + limits echo, env default, dedup - gRPC error -> 503 provision_failed (+ soft-delete) on every arm - persist failure (bad AES key) -> 503 + best-effort gRPC DeprovisionResource (the deprovisionBestEffort non-nil-client path, previously 0%) - dedicated tier-gate (402) + dedicated growth success - single-twin (dev env) + bulk-twin via ProvisionForTwinCore over gRPC - queue per-tier count cap, cross-service daily-cap 429, invalid-team 400 - anon dedup with corrupted ciphertext (decrypt-fail fall-through) - resource Delete deprovision-via-gRPC + cross-team/bad-uuid/not-found - webhook authenticated, anon-dedup, cross-service branches Production behaviour is unchanged: NewClientFromConn is the only new export and merely wraps an existing conn (NewClient still owns the dial in prod). Aggregate over the resource files: 74.9% -> 79.8%. Per-file: db 87.4%, cache 80.5%, nosql 81.9%, queue 81.6%, webhook 78.8%, provision_helper 80.5% (storage/resource broker + deep-fault branches remain). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
provisioner.NewClientFromConn(conn, secret)so handler tests can inject a bufconn-backed*provisioner.Client. This lets theprovClient != nilarms ofprovisionDB/provisionCache/provisionNoSQL/provisionQueueactually execute (they previously 503'd in tests with no gRPC seam, capping coverage at ~75%).ProvisionerServiceServeron agoogle.golang.org/grpc/test/bufconnlistener and drive: gRPC provision success (anon + authenticated, tier/limits echo, env default, dedup), gRPC error → 503 (+soft-delete), persist failure → 503 + best-effortDeprovisionResource(thedeprovisionBestEffortnon-nil path, previously 0%), dedicated tier-gate + growth success, single-twin (dev env) + bulk-twin via gRPC, queue count cap, cross-service 429, invalid-team 400, decrypt-fail dedup, resource Delete deprovision-via-gRPC, and webhook authenticated/dedup/cross-service branches.NewClientFromConnis the only new export and merely wraps an already-dialed conn;NewClientstill owns the dial in prod.Coverage (statement-level, target files)
Aggregate 74.9% → 79.8%. Per-file: db 87.4%, cache 80.5%, nosql 81.9%, queue 81.6%, webhook 78.8%, provision_helper 80.5%, resource 76.4%, resource_metrics 92.5%, storage 70.0%.
Note: the ≥95% goal was not fully reached. The remaining gap is concentrated in storage.go broker-mode/presign (needs a
PrefixScopedKeys=falseprovider stub) and resource.go provider faults — out of scope for the bufconn provision-arm focus and tracked as follow-up.Test plan
go test ./... -short -p 1)go build ./...+go vet ./...cleango test ./internal/handlers ./internal/provisioner -p 1green on a fresh test DB🤖 Generated with Claude Code